//
//  LGTPostDetailTaskInfoViewCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/27.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTPostDetailTaskInfoViewCell: UITableViewCell {

    var titleLabel:UILabel?
    var topTimeLabel:UILabel?
    var workTimeLabel:UILabel?
    var reviewTimeLabel:UILabel?
    var workTimesLabel:UILabel?
    var offlieLabel:UILabel?
    
    private var _model:Dictionary<String, Any>?
    var model:Dictionary<String, Any>{
        get{
            return _model ?? Dictionary.init()
        }set{
            _model = newValue
            self.setData()
        }
    }
    
    func setData(){
        
        self.topTimeLabel?.text = self.model["topTimeStr"] as? String ?? ""
        self.workTimeLabel?.text = self.model["workTime"] as? String ?? ""
        self.reviewTimeLabel?.text = self.model["reviewTime"] as? String ?? ""
        self.workTimesLabel?.text = self.model["workTimes"] as? String ?? ""
        self.offlieLabel?.text = self.model["offline"] as? String ?? ""
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(16), text: "基本信息")
        self.titleLabel?.numberOfLines = 0
        self.addSubview(self.titleLabel!)
        self.titleLabel!.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(13))
            make.top.equalTo(SizeFit(14))
            make.height.equalTo(SizeFitFloat(17))
        }
        
        let line:UIImageView = LGTViewCreateUtil.share.createLineView()
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(13))
            make.right.equalTo(-SizeFit(11))
            make.height.equalTo(1)
            make.top.equalTo(SizeFit(36))
        }
        
        let titleArray:Array<String> = ["置顶天数：", "做单时间：", "审核时间：", "做单次数：", "下线时间："]
        self.topTimeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(12))
        self.workTimeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(12))
        self.reviewTimeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(12))
        self.workTimesLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(12))
        self.offlieLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(12))
        let labelArray:Array<UILabel> = [self.topTimeLabel!, self.workTimeLabel!, self.reviewTimeLabel!, self.workTimesLabel!, self.offlieLabel!]
        
        let topY:CGFloat = SizeFitFloat(53)
        let x0:CGFloat = SizeFitFloat(13)
        let h:CGFloat = SizeFitFloat(12)
        let itemH:CGFloat = SizeFitFloat(24)
        
        //任务
        for i in 0..<titleArray.count{
            let title:String = titleArray[i]
            let descLabel:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: GrayColor, fontSize: SizeFitFloat(12), text: title)
            self.addSubview(descLabel)
            descLabel.snp.makeConstraints { (make) in
                make.left.equalTo(x0)
                make.top.equalTo(topY + itemH * CGFloat(i))
                make.height.equalTo(h)
            }
            
            let label:UILabel = labelArray[i]
            self.addSubview(label)
            label.snp.makeConstraints { (make) in
                make.left.equalTo(descLabel.snp_rightMargin).offset(SizeFit(5))
                make.centerY.equalTo(descLabel)
                make.height.equalTo(SizeFitFloat(13))
            }
        }
        
        let line2:UIImageView = LGTViewCreateUtil.share.createLineView()
        line2.isHidden = true
        self.addSubview(line2)
        line2.snp.makeConstraints{ (make) in
            make.bottom.equalTo(0)
            make.top.equalTo(self.offlieLabel!.snp_bottomMargin).offset(SizeFitFloat(14))
            make.height.equalTo(1)
            make.width.equalTo(100)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
